home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / ActionFeat < prev    next >
Text File  |  1995-06-28  |  4KB  |  134 lines

  1. Action Features
  2. Previous: <Error Reporting=>ErrorRepor> * Next: <Algorithm=>Algorithm> * Up: <Interface=>Interface>
  3.  
  4. #Wrap on
  5. {fH3}Special Features for Use in Actions{f}
  6.  
  7. Here is a table of Bison constructs, variables and macros that
  8. are useful in actions.
  9.  
  10. #Indent +4
  11. #Indent
  12. {fEmphasis}$${f}
  13. #Indent +4
  14. Acts like a variable that contains the semantic value for the
  15. grouping made by the current rule.  \*Note <Actions=>Actions>.
  16.  
  17. #Indent
  18. {fEmphasis}${fStrong}n{f}{f}
  19. #Indent +4
  20. Acts like a variable that contains the semantic value for the
  21. {fStrong}n{f}th component of the current rule.  \*Note <Actions=>Actions>.
  22.  
  23. #Indent
  24. {fEmphasis}$<{fStrong}typealt{f}>${f}
  25. #Indent +4
  26. Like {fCode}$${f} but specifies alternative {fStrong}typealt{f} in the union
  27. specified by the {fCode}%union{f} declaration.  \*Note <Action Types=>ActionType>: Data Types of Values in Actions.
  28.  
  29. #Indent
  30. {fEmphasis}$<{fStrong}typealt{f}>{fStrong}n{f}{f}
  31. #Indent +4
  32. Like {fCode}${fStrong}n{f}{f} but specifies alternative {fStrong}typealt{f} in the
  33. union specified by the {fCode}%union{f} declaration.  
  34. \*Note <Action Types=>ActionType>: Data Types of Values in Actions.
  35.  
  36. #Indent
  37. {fEmphasis}YYABORT;{f}
  38. #Indent +4
  39. Return immediately from {fCode}yyparse{f}, indicating failure.
  40. \*Note <Parser Function=>ParserFunc>: The Parser Function {fCode}yyparse{f}.
  41.  
  42. #Indent
  43. {fEmphasis}YYACCEPT;{f}
  44. #Indent +4
  45. Return immediately from {fCode}yyparse{f}, indicating success.
  46. \*Note <Parser Function=>ParserFunc>: The Parser Function {fCode}yyparse{f}.
  47.  
  48. #Indent
  49. {fEmphasis}YYBACKUP ({fStrong}token{f}, {fStrong}value{f});{f}
  50. #Indent +4
  51. Unshift a token.  This macro is allowed only for rules that reduce
  52. a single value, and only when there is no look-ahead token.
  53. It installs a look-ahead token with token type {fStrong}token{f} and
  54. semantic value {fStrong}value{f}; then it discards the value that was
  55. going to be reduced by this rule.
  56.  
  57. If the macro is used when it is not valid, such as when there is
  58. a look-ahead token already, then it reports a syntax error with
  59. a message {fEmphasis}cannot back up{f} and performs ordinary error
  60. recovery.
  61.  
  62. In either case, the rest of the action is not executed.
  63.  
  64. #Indent
  65. {fEmphasis}YYEMPTY{f}
  66. #Indent +4
  67. Value stored in {fCode}yychar{f} when there is no look-ahead token.
  68.  
  69. #Indent
  70. {fEmphasis}YYERROR;{f}
  71. #Indent +4
  72. Cause an immediate syntax error.  This statement initiates error
  73. recovery just as if the parser itself had detected an error; however, it
  74. does not call {fCode}yyerror{f}, and does not print any message.  If you
  75. want to print an error message, call {fCode}yyerror{f} explicitly before
  76. the {fEmphasis}YYERROR;{f} statement.  \*Note <Error Recovery=>ErrorRecov>.
  77.  
  78. #Indent
  79. {fEmphasis}YYRECOVERING{f}
  80. #Indent +4
  81. This macro stands for an expression that has the value 1 when the parser
  82. is recovering from a syntax error, and 0 the rest of the time.
  83. \*Note <Error Recovery=>ErrorRecov>.
  84.  
  85. #Indent
  86. {fEmphasis}yychar{f}
  87. #Indent +4
  88. Variable containing the current look-ahead token.  (In a pure parser,
  89. this is actually a local variable within {fCode}yyparse{f}.)  When there is
  90. no look-ahead token, the value {fCode}YYEMPTY{f} is stored in the variable.
  91. \*Note <Look-Ahead=>LookAhead>: Look-Ahead Tokens.
  92.  
  93. #Indent
  94. {fEmphasis}yyclearin;{f}
  95. #Indent +4
  96. Discard the current look-ahead token.  This is useful primarily in
  97. error rules.  \*Note <Error Recovery=>ErrorRecov>.
  98.  
  99. #Indent
  100. {fEmphasis}yyerrok;{f}
  101. #Indent +4
  102. Resume generating error messages immediately for subsequent syntax
  103. errors.  This is useful primarily in error rules.  
  104. \*Note <Error Recovery=>ErrorRecov>.
  105.  
  106. #Indent
  107. {fEmphasis}@{fStrong}n{f}{f}
  108. #Indent +4
  109. Acts like a structure variable containing information on the line
  110. numbers and column numbers of the {fStrong}n{f}th component of the current
  111. rule.  The structure has four members, like this:
  112.  
  113. #Wrap off
  114. #fCode
  115. struct \{
  116.   int first\_line, last\_line;
  117.   int first\_column, last\_column;
  118. \};
  119. #f
  120. #Wrap on
  121.  
  122. Thus, to get the starting line number of the third component, use
  123. {fEmphasis}@3.first\_line{f}.
  124.  
  125. In order for the members of this structure to contain valid information,
  126. you must make {fCode}yylex{f} supply this information about each token.
  127. If you need only certain members, then {fCode}yylex{f} need only fill in
  128. those members.
  129.  
  130. The use of this feature makes the parser noticeably slower.
  131.  
  132. #Indent
  133.  
  134.